package tech.pdai.springframework.context;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * 初始化前后执行
 */
@Component
public class CarBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.contains("car")) {
            System.out.println("这是一个CarBeanPostProcessor的初始化前的init方法");
        }
        return null;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.contains("car")) {
            System.out.println("这是一个CarBeanPostProcessor的初始化后的init方法");
        }
        return null;
    }
}
